#!/bin/zsh
###
 # @Author: jiu yin
 # @Date: 2023-11-03 17:31:09
 # @LastEditTime: 2023-11-03 17:39:44
 # @LastEditors: jiu yin zhen jing
 # @FilePath: \ai-admin\local.sh
 # jiu
###

name=gl

work_path=$(pwd)

echo '删除'$name'dist文件'

rm -rf dist

echo '开始编译'
# npm install
# npm install sass
npm run $1
echo '编译完成'

echo '开始打包...删除文件夹'

rm -rf /tmp/$name/

echo '开始打包...创建文件夹'

mkdir /tmp/$name/

echo '开始打包...拷贝文件'

cp -rf dist/* /tmp/$name/

cd /tmp/

echo '开始打包'

tar -czvf $name.tar.gz $name/

mv $name.tar.gz ${work_path}

# 回到当前工程目录
cd ${work_path}

echo '上传文件'
if [ "$1" = "test" ]; then
    scp $name.tar.gz root@192.168.0.32:/applications/meta-web/html/
fi
echo '上传完成'

# 回到当前工程目录
cd ${work_path}
echo '服务器执行重启服务脚本'
if [ "$1" = "test" ]; then
    ssh root@192.168.0.32 "cd /applications/meta-web/html/; rm -rf $name; tar -zxvf $name.tar.gz;"
fi

# rm $name
rm $name.tar.gz

echo 'All Done'